package tjava.apt;

import java.util.List;

import com.sun.mirror.apt.AnnotationProcessor;
import com.sun.mirror.apt.AnnotationProcessorEnvironment;
import com.sun.mirror.declaration.AnnotationMirror;
import com.sun.mirror.declaration.TypeDeclaration;
import com.sun.mirror.util.DeclarationVisitor;
import com.sun.mirror.util.DeclarationVisitors;

public class TjavaGeneratorProcessor implements AnnotationProcessor {

	AnnotationProcessorEnvironment env;

	public TjavaGeneratorProcessor(final AnnotationProcessorEnvironment env) {
		this.env = env;
	}

	public void process() {

		DeclarationVisitor visitor = DeclarationVisitors
				.getSourceOrderDeclarationScanner(new ClassVisitor(env),
						DeclarationVisitors.NO_OP);

		for (TypeDeclaration typeDeclaration : env.getTypeDeclarations()) {
			List<AnnotationMirror> annotationMirrors = (List<AnnotationMirror>) typeDeclaration
					.getAnnotationMirrors();
			for (AnnotationMirror annotationMirror : annotationMirrors) {
				if (annotationMirror.getAnnotationType().getDeclaration()
						.getSimpleName().equals("TemplateInstance")) {

					typeDeclaration.accept(visitor);
				}
			}
		}
	}
}